package vue;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.BoxLayout;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.border.LineBorder;

import java.awt.Color;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;

import java.awt.CardLayout;

import javax.swing.JTextArea;
import javax.swing.JTextField;

import metier.dao.IDAO;
import metier.dao.NewsDao;
import metier.modele.NewsModele;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class AjouterNews extends JFrame {

	private JPanel contentPane;
	private JTable table;
	private JTable table_1;
	private JTable table_2;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;

	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					AjouterNews frame = new AjouterNews();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}*/
	public void close()
	{
		this.dispose();
	}
	public void refreshPage()
	{
		this.repaint();
	}
	/**
	 * Create the frame.
	 */
	public AjouterNews() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 883, 729);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(0, 0, 234, 25);
		contentPane.add(panel);
		panel.setLayout(new GridLayout(0, 1, 0, 0));
		
		JMenuBar menuBar = new JMenuBar();
		panel.add(menuBar);
		
		JButton btnAccueil = new JButton("Accueil");
		btnAccueil.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Accueil accueilVue = new Accueil();
				accueilVue.setVisible(true);
				close();
			}
		});
		menuBar.add(btnAccueil);
		
		JButton btnNewButton = new JButton("Consulter");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Consulter consulterVue = new Consulter();
				consulterVue.setVisible(true);
				close();
			}
		});
		menuBar.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("Editer");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Editer editerVue = new Editer();
				editerVue.setVisible(true);
				close();
			}
		});
		menuBar.add(btnNewButton_1);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBounds(54, 124, 252, 321);
		contentPane.add(panel_1);
		panel_1.setLayout(new GridLayout(0, 1, 0, 0));
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		panel_1.add(tabbedPane);
		
		JScrollPane scrollPane = new JScrollPane();
		tabbedPane.addTab("Lieu", null, scrollPane, null);
		
		table = new JTable();
		table.setRowHeight(25);
		scrollPane.setViewportView(table);
		table.setModel(new DefaultTableModel(
			new Object[][] {
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
			},
			new String[] {
				"Lieu"
			}
		) {
			Class[] columnTypes = new Class[] {
				String.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
			boolean[] columnEditables = new boolean[] {
				false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		
		JPanel panel_2 = new JPanel();
		panel_2.setToolTipText("P");
		tabbedPane.addTab("Point d'inter\u00EAt", null, panel_2, null);
		panel_2.setLayout(new GridLayout(0, 1, 0, 0));
		
		JScrollPane scrollPane_1 = new JScrollPane();
		panel_2.add(scrollPane_1);
		
		table_1 = new JTable();
		table_1.setRowHeight(25);
		scrollPane_1.setViewportView(table_1);
		table_1.setModel(new DefaultTableModel(
			new Object[][] {
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
			},
			new String[] {
				"Point d'inter\u00EAt"
			}
		) {
			Class[] columnTypes = new Class[] {
				String.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
			boolean[] columnEditables = new boolean[] {
				false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		
		JPanel panel_3 = new JPanel();
		tabbedPane.addTab("Parcours", null, panel_3, null);
		panel_3.setLayout(new GridLayout(0, 1, 0, 0));
		
		JScrollPane scrollPane_2 = new JScrollPane();
		panel_3.add(scrollPane_2);
		
		table_2 = new JTable();
		table_2.setRowHeight(25);
		scrollPane_2.setViewportView(table_2);
		table_2.setModel(new DefaultTableModel(
			new Object[][] {
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
				{null},
			},
			new String[] {
				"Parcours"
			}
		) {
			Class[] columnTypes = new Class[] {
				String.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
			boolean[] columnEditables = new boolean[] {
				false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		
		JLabel lblAjouternews = new JLabel("Ajouter News");
		lblAjouternews.setFont(new Font("Tahoma", Font.PLAIN, 18));
		lblAjouternews.setBounds(391, 55, 131, 31);
		contentPane.add(lblAjouternews);
		
		JPanel panel_4 = new JPanel();
		panel_4.setBorder(new LineBorder(new Color(0, 0, 0)));
		panel_4.setBounds(448, 136, 391, 533);
		contentPane.add(panel_4);
		panel_4.setLayout(null);
		
		JLabel lblLibell = new JLabel("Libell\u00E9");
		lblLibell.setBounds(20, 11, 46, 14);
		panel_4.add(lblLibell);
		
		JLabel lblDescriptif = new JLabel("Descriptif");
		lblDescriptif.setBounds(20, 82, 86, 14);
		panel_4.add(lblDescriptif);
		
		JLabel lblImage = new JLabel("Image");
		lblImage.setBounds(20, 308, 46, 14);
		panel_4.add(lblImage);
		
		final JTextArea textArea = new JTextArea();
		textArea.setBounds(20, 118, 264, 95);
		panel_4.add(textArea);
		
		textField = new JTextField();
		textField.setBounds(20, 36, 86, 20);
		panel_4.add(textField);
		textField.setColumns(10);
		
		JPanel panel_5 = new JPanel();
		panel_5.setBorder(new LineBorder(new Color(0, 0, 0)));
		panel_5.setBounds(20, 335, 359, 149);
		panel_4.add(panel_5);
		
		JButton btnValider = new JButton("Valider");
		btnValider.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				String libelle;
				String description;
				String lien;
				String image;
				
				libelle = textField.getText();
				description = textArea.getText();
				lien = textField_2.getText();
				image = textField_1.getText();
						
				NewsModele newsmodele = new NewsModele(libelle, description, lien, image);
				IDAO dao = (IDAO) new NewsDao();
				dao.ajouter(newsmodele);
			}
		});
		btnValider.setBounds(290, 497, 89, 23);
		panel_4.add(btnValider);
		
		JButton btnBrowse = new JButton("Browse");
		btnBrowse.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				JFileChooser chooser = new JFileChooser(".");
				int status = chooser.showOpenDialog(AjouterNews.this);
				if(status == JFileChooser.APPROVE_OPTION) {
					try {
						JPanel panel_3 = new JPanel();
					    JFrame frame = new JFrame();    
					    frame.pack();  
					    frame.setVisible(true);  
					}
					catch (Exception e2)
					{
						System.err.println("Error : " + e2);
					}
				}
			}
		});
		btnBrowse.setBounds(70, 304, 98, 23);
		panel_4.add(btnBrowse);
		
		textField_1 = new JTextField();
		textField_1.setEditable(false);
		textField_1.setBounds(189, 304, 190, 22);
		panel_4.add(textField_1);
		textField_1.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("Lien");
		lblNewLabel.setBounds(20, 244, 86, 16);
		panel_4.add(lblNewLabel);
		
		textField_2 = new JTextField();
		textField_2.setBounds(70, 241, 192, 22);
		panel_4.add(textField_2);
		textField_2.setColumns(10);
	}
}
